#ifndef __SDCARD_H__
#define __SDCARD_H__
#include "stm32f10x.h"

class SDCard
{
	public:
		enum SDType_t
		{
		    V1,
		    V2,
		    V2HC,
		};
		enum SDResault_t
		{
		    ERROR,
		    TIMEOUT,
		    OK
		};
	private:
		uint32_t dbuf[512/4];
		const SDIO& Port;
		SDResault_t PowerOn(void);
		SDResault_t CheckReturn(uint8_t CMD, uint32_t Flag, uint32_t& Resp) const;
	protected:

	public:
		SDType_t Type;
		uint32_t RCA,OCR;
		uint32_t CID[4],CSD[4];
		static const char *TypeToString[];
		static const char *ResaultToString[];
		SDCard(const SDIO& _Port): Port(_Port) {};
		SDResault_t Init(void);
		SDResault_t WriteBlock(const uint32_t Sector, uint8_t *buf);
		SDResault_t ReadBlock(const uint32_t Sector, uint8_t *buf);
		SDResault_t SetBolckSize(const uint32_t Size = 512) const;
};

#endif
